﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using app_common;
using System.Collections;

namespace tpos_dataaccess
{
    public class clsDataAccess
    {
        clsWriteFile clswl = new clsWriteFile();

        public DataTable getTableBySql(string sql)
        {
            try { 
                Hashtable hashResult = APP_SQL_COMMAND.ExecuteReader(sql);
                if (hashResult[STATUS_MESSAGE.MESSAGE].ToString() == STATUS_MESSAGE.ERROR)
                {
                    clswl.write_line(hashResult[STATUS_MESSAGE.VALUE].ToString());                    
                }
                else
                {
                    DataTable dtResult = (DataTable)hashResult[STATUS_MESSAGE.VALUE];
                    if (dtResult.Rows.Count > 0) return dtResult;
                    else return null;
                }
            }
            catch { return null; }
            return null;
        }

        public int updateTableBySql(string sql)
        {
            try
            {
                Hashtable hashResult = APP_SQL_COMMAND.ExecuteReader(sql);
                if (hashResult[STATUS_MESSAGE.MESSAGE].ToString() == STATUS_MESSAGE.ERROR)
                {
                    clswl.write_line(hashResult[STATUS_MESSAGE.VALUE].ToString());
                }
                else
                {
                    return (int)hashResult[STATUS_MESSAGE.VALUE];
                }
            }
            catch { return 0; }
            return 0;
        }

    }
}
